package com.credithc.fastdfs.api.service.impl;

import java.util.Map;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.credithc.fastdfs.api.entity.FdfsInfo;
import com.credithc.fastdfs.api.mapper.FdfsInfoMapper;
import com.credithc.fastdfs.api.service.FdfsInfoService;
import com.credithc.framework.core.mybatis.page.PageController;
/**
 * @ClassName: FdfsInfoServiceImpl 
 * @Description: 文件操作实现
 * @author zhaoc
 * @date 2015年5月14日
 * @time  上午9:03:39
 */
@Service("fdfsInfoServiceImpl")
public class FdfsInfoServiceImpl implements FdfsInfoService {
	@Autowired
	private FdfsInfoMapper fdfsInfoMapper;

	@Override
	public void insertFdfsInfo(FdfsInfo info)  throws Exception{
		fdfsInfoMapper.insert(info);
	}

	@Override
	public FdfsInfo selectByPrimaryKey(String fsId)  throws Exception{
		return fdfsInfoMapper.selectByPrimaryKey(fsId);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
	public int updateStatusByPrimaryKey(String fsId, int stat)  throws Exception{
		FdfsInfo info = new FdfsInfo();
		info.setFsId(fsId);
		info.setFileSaveStatus(stat);
		return fdfsInfoMapper.updateByPrimaryKeySelective(info);
	}
	
	@Override
	public List<String> selectFsIdBySystemIdAndBusinessId(PageController page, String systemId, String businessId)  throws Exception{
		return fdfsInfoMapper.selectFsIdBySystemIdAndBusinessId(page, systemId, businessId);
	}
	
	@Override
	public Integer selectFsIdCountBySystemIdAndBusinessId(String systemId, String businessId)  throws Exception{
		return fdfsInfoMapper.selectFsIdCountBySystemIdAndBusinessId(systemId, businessId);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
	public int updateFileDownloadCounts(Map map)  throws Exception{
		return fdfsInfoMapper.updateFileDownloadCounts(map);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
	public int updateFdfsInfoByPrimaryKey(FdfsInfo info)  throws Exception{
		return fdfsInfoMapper.updateByPrimaryKeySelective(info);
	}
}
